package com.wfk.service.impl;

import com.wfk.entity.SysRule;
import com.wfk.mapper.SysRuleMapper;
import com.wfk.service.ISysRuleService;
import com.wfk.utils.BasePage;
import com.wfk.utils.ResponseData;
import com.wfk.utils.ValidateUtil;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

/**
 * <p>
 * 平台规则 服务实现类
 * </p>
 *
 * @since 2019-01-11
 */
@Service
public class SysRuleServiceImpl extends ServiceImpl<SysRuleMapper, SysRule> implements ISysRuleService {

	@Override
	public SysRule getTitle(String title) {
		QueryWrapper<SysRule> queryWrapper = new QueryWrapper<SysRule>();
		queryWrapper.eq("title", title);
		return super.getOne(queryWrapper);
	}

	@Override
	public BasePage<SysRule> getLit(SysRule vo, BasePage<SysRule> page) {
		if(page.isPage()) {
			super.page(page, null);
		}else {
			page.setRecords(super.list(null));
		}
		return page;
	}

	@Override
	public ResponseData saveSysRule(SysRule sysRule) {
		if (!ValidateUtil.empty(sysRule.getTitle())) {
			return ResponseData.baseServiceError("标题不能为空");
		}
		if (!ValidateUtil.empty(sysRule.getContent())) {
			return ResponseData.baseServiceError("内容不能为空");
		}
		super.saveOrUpdate(sysRule);
		return ResponseData.ok();
	}

}
